﻿using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace Kugar.Core.PluginFramework.Host
{
    internal class JObjectToDictionary : IEnumerable<KeyValuePair<string, object>>
    {
        private JObject _value = null;

        public JObjectToDictionary(JObject value)
        {
            _value = value;
        }

        public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
        {
            if (_value==null)
            {
                yield break;
            }

            foreach (var property in _value)
            {
                yield return new KeyValuePair<string, object>(property.Key, property.Value);
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}